﻿using System;
using System.Collections;
using System.Data;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Text;
using Rison.DataAccess.Data.ZJCP;

namespace Rison.Web.ZJCP.ashx
{
    /// <summary>
    /// $codebehindclassname$ 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class load_vote_departs : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            context.Response.Write(String.Format("_departs = {0};", loadVoteDeparts()));
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
        private string loadVoteDeparts()
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("SELECT     DepartID, DepartName,");
            sql.Append("                          (SELECT     COUNT(1) AS Expr1");
            sql.Append("                            FROM          Vote AS t1");
            sql.Append("                            WHERE      (depart_id = t.DepartID) AND (vo_grade = '满意')) AS good,");
            sql.Append("                          (SELECT     COUNT(1) AS Expr1");
            sql.Append("                            FROM          Vote AS t1");
            sql.Append("                            WHERE      (depart_id = t.DepartID) AND (vo_grade = '一般')) AS normal,");
            sql.Append("                          (SELECT     COUNT(1) AS Expr1");
            sql.Append("                            FROM          Vote AS t1");
            sql.Append("                            WHERE      (depart_id = t.DepartID) AND (vo_grade = '不满意')) AS bad");
            sql.Append(" FROM         Department AS t");
            sql.Append(" ORDER BY OrderName");
            DataSet ds = DbAccess.executeQuery(sql.ToString());
            return JsonCommon.ds2json(ds);
        }
    }
}
